﻿@using Fierce.MvcExtend.Controls.Manage

<div class="easyui-layout" data-options="fit:true">

    <div data-options="region:'north',border:false,height:112">
        <div class="document-name">@ViewBag.Work.Menu.Name</div>
        <div class="document-toolbar">@Easyui.Toolbar(ViewBag.Work)</div>
    </div>

    <div data-options="region:'center',border:false"><table id="igrid" /></div>

</div>

<script type="text/javascript">
    $(function () {
        //表格初始化
        var gridInit = function () {
            $("#igrid").datagrid({
                url: "/basic/function/grid",
                nowrap: false,
                rownumbers: true,
                fit: true,
                singleSelect: true,
                idField: "ID",
                pageSize: 20,
                pagination: true,
                columns: [[
                    {
                        field: "Icon", title: "图标", width: 50, align: "center",
                        formatter: function (value, row, index) {
                            if (value) { return manage.icon(value); }
                        }
                    },
                    { field: "Name", title: "名称", width: 80, align: "center" },
                    { field: "Type", title: "类型", width: 80, align: "center" },
                    { field: "Sequence", title: "排序", width: 50, align: "center" },
                    { field: "Func", title: "功能", width: 100, align: "center" },
                    { field: "Purview", title: "权限", width: 100, align: "center" },
                    { field: "Remark", title: "描述", width: 280, align: "center" }
                ]]
            });
        }();
        //添加
        var insert = function () {
            mutual("添加", null);
        };
        //修改
        var update = function () {
            var row = $("#igrid").datagrid("getSelected");
            if (row) {
                mutual("修改", row.ID);
            }
            else { manage.slide(manage.nullRowMsg); }
        };
        //删除
        var remove = function () {
            var row = $("#igrid").datagrid("getSelected");
            if (row) {
                manage.confirm("确认删除?", function (del) {
                    if (del) {
                        manage.ajax({
                            url: "/basic/function/remove",
                            type: "post", data: { id: row.ID },
                            success: function (result) {
                                manage.slide(result.message);
                                if (result.success) { reload(); }
                            }
                        });
                    }
                });
            }
            else { manage.slide(manage.nullRowMsg); }
        };
        //实体操作
        var mutual = function (title, id) {
            var href = "/basic/function/page?" + $.param({ id: id });
            var d = manage.dialog({
                title: title, href: href, width: 420,
                bodyCls: "theme-container",
                handler: function () {
                    manage.form({
                        dialog: d, formid: "#dform",
                        url: "/basic/function/save",
                        success: function (result) { reload(); }
                    });
                },
                onLoad: function () { formInit(); }
            });
        };
        //弹窗初始化
        var formInit = function () {
            $("#iptIcon").textbox({
                required: true, editable: false,
                icons: [{
                    iconCls: "icon-application-view-icons",
                    handler: function () {
                        var d = manage.dialog({
                            title: "选择图标",
                            id: "iptIconBox",
                            width: 542, height: 460,
                            iconCls: "icon-bricks",
                            href: "/content/easyui/extensions/icons/select.html",
                            onLoad: function () {
                                $("span.list-span", "#iptIconBox").click(function () {
                                    var value = $(this).data("value");
                                    d.dialog("close");
                                    $("#iptIcon").textbox("setValue", value);
                                });
                            }
                        });
                    }
                }]
            });
        };
        //排序上移
        var desc = function () {
            order("desc");
        };
        //排序下移
        var asc = function () {
            order("asc");
        };
        //排序操作
        var order = function (order) {
            var row = $("#igrid").datagrid("getSelected");
            if (row) {
                manage.ajax({
                    url: "/basic/function/setorder",
                    type: "post", data: { id: row.ID, order: order },
                    success: function (result) {
                        manage.slide(result.message);
                        if (result.success) {
                            $("#igrid").datagrid("reload");
                        }
                    }
                });
            }
            else { manage.slide(manage.nullRowMsg); }
        };
        //刷新列表
        var reload = function () {
            $("#igrid").datagrid("unselectAll");
            $("#igrid").datagrid("reload");
        };
        //按钮事件
        manage.buttonInit("basicfunction", function (f) { return eval(f); });
    });
</script>